const toRad = (a: number) => (a * Math.PI) / 180;
const distanceCalculate = function (
  lat1: number,
  lng1: number,
  lat2: number,
  lng2: number,
) {
  const radLat1 = toRad(lat1);
  const radLat2 = toRad(lat2);
  const deltaLat = toRad(lat1) - toRad(lat2);
  const deltaLng = toRad(lng1) - toRad(lng2);
  const space =
    2 *
    Math.asin(
      Math.sqrt(
        Math.pow(Math.sin(deltaLat / 2), 2) +
          Math.cos(radLat1) *
            Math.cos(radLat2) *
            Math.pow(Math.sin(deltaLng / 2), 2),
      ),
    );
  return space * 6378137;
};
export { distanceCalculate };
